home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 November / Macworld (1999-11).dmg / Updaters / WhiteCap 3.0.4 / WhiteCap Source.sit / WhiteCap Source / Common / General Tools / Headers / UnionFind.h < prev    next >
Text File  |  1999-07-13  |  636b  |  41 lines

  1. #ifndef _UnionFind_
  2. #define _UnionFind_
  3.  
  4. /* 
  5. An implementation of the famous union-find algorithm.
  6. */
  7.  
  8. class XLongList;
  9.  
  10.  
  11. class UnionFind {
  12.  
  13.     
  14.     public:
  15.                             UnionFind();
  16.         virtual                ~UnionFind();
  17.             
  18.         // Helps UnionFind make a good size ahead of time
  19.         void                Dim( long inNum )                { Find( inNum - 1 );    }
  20.         
  21.         void                Union( long inA, long inB );
  22.     
  23.         long                Find( long inA );
  24.         
  25.         long                LargestSet( long* outSize );
  26.         
  27.         void                EnumerateSet( long inSetID, XLongList& outSet );
  28.                         
  29.         long                NumSets();
  30.         
  31.         void                GetSets( XLongList& outSets );
  32.         
  33.     protected:
  34.         long                mDimSize;
  35.         unsigned short*        mElements;
  36.     
  37. };
  38.  
  39.  
  40.  
  41. #endif